package com.yooli.credit.base.lazybonessso.rest.test;


import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/test/webflux")
public class WebFluxController {
    @RequestMapping(value = "/fluxTest",method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public Mono<String>  testMono(@RequestHeader(HttpHeaders.AUTHORIZATION) String author){
        String jwStr = author.replace("Beanrer","");
        System.out.println(jwStr);
        //两种方法可以让逻辑方法返回到前端
       // return Mono.justOrEmpty(jwStr);
        return  Mono.create(cityMonoSink -> {
            String data = ("monoTest()");
            cityMonoSink.success(data);
            cityMonoSink.error(new Exception());
        });
    }
    @RequestMapping(value = "/fluxListTest",method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public Flux<List<String>> testLitFlux(@RequestHeader(HttpHeaders.AUTHORIZATION) String author){
        List<String>  list = new ArrayList<String>();
        list.add("1");
        list.add("a");
        list.add("2");
        list.add("b");
        return Flux.fromIterable(Collections.singleton(list));
    }

}
